#ifndef CAMERADEVICE_H
#define CAMERADEVICE_H

#include "camera.h"

struct axidma_dev;
struct array;
class QTimer;
class CameraDevice : public Camera
{
    Q_OBJECT
public:
    CameraDevice();
    ~CameraDevice() override;

    int cameraInit() override;

    int cameraReset() override;

    int trigger() override;

    int setTriggerSource(unsigned char source) override;
    unsigned char getTriggerSource() const override;

    //曝光时间参数单位为ms
    int setExposureTime(unsigned short time) override;
    unsigned short getExposureTime() const override;

    //FPGA没有提供功能接口，需要调用sensor接口对sensor寄存器进行设置
    int setAnologGain(unsigned char gain) override;
    unsigned char getAnologGain() const override;

    short getSensorTemperature() const override;
    short getFpgaBoardTemperature() const override;

    int setpictureMode(unsigned char mode) override;
    unsigned char getPictureMode() const override;

    int setFrameRate(unsigned short rate) override;
    unsigned short getFrameRate() const override;

private:
    //DMA设备接口,外设直接与内存交换数据，仅在传输开始和结束时通知 CPU（通过中断）
    axidma_dev *axidma_dev_;
    //DMA控制的内存
    unsigned char *rx_buf_;
    //DMA接收通道数组
    const array *rx_chans_;

    //时时检测是否获得图像数据
    QTimer *image_capture_time_;
    //指向图像数据头指针
    unsigned char *image_ptr_;

    unsigned short exposure_low_limit_ = 58;
    unsigned short exposure_high_limit_ = 65535;
    unsigned char anolog_gain_low_limit_ = 11;
    unsigned char anolog_gain_heig_limit = 50;

private:
    int initializeSensor();
    int initializeFPGA();
    int initializeCameraParameter();
    int initializeDMA();
private slots:
    void onSendCaptureImageSignal();
};

#endif // CAMERADEVICE_H
